package org.kaer.election.utils;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.util.DisplayMetrics;

public class BitmapUtils {

	public static Bitmap scaleBitmap(Bitmap srcBm, double newWidth, int newHeight) {
		float scaleX = (float) (newWidth / srcBm.getWidth());
		float scaleY = (float) (newHeight / srcBm.getHeight());
		Matrix matrix = new Matrix();
		matrix.postScale(scaleX, scaleY);
		return Bitmap.createBitmap(srcBm, 0, 0, srcBm.getWidth(), srcBm.getHeight(), matrix, true);
	}

	public static Bitmap scaleBitmap(Bitmap srcBm, double newWidth) {
		float scaleX = (float) (newWidth / srcBm.getWidth());
		Matrix matrix = new Matrix();
		matrix.postScale(scaleX, scaleX);
		return Bitmap.createBitmap(srcBm, 0, 0, srcBm.getWidth(), srcBm.getHeight(), matrix, true);
	}

	public static Bitmap scaleBitmap(Context mContext, Bitmap srcBm, double scale) {
		DisplayMetrics metrics = new DisplayMetrics();
		((Activity) mContext).getWindowManager().getDefaultDisplay().getMetrics(metrics);
		System.out.println("scale = " + scale);
		System.out.println(metrics.toString());
		double newWidth = metrics.widthPixels * scale;
		return scaleBitmap(srcBm, newWidth);
	}
}
